<?php
namespace zake\server;

use zake\helper\Grant;
use zake\foundation\reactor\trigger\Listen;

/**
 * Class Server
 * @package zake\server
 *
 * @author liu.bin 2020-04-30 16:40
 */
class Server extends BaseServer
{

    /**
     * @var array
     */
    protected $_listenList = [];

    /**
     * @var Server
     */
    private static $singleton = null;

    /**
     * 单例构造器
     * @return Server
     * @author liu.bin 2020-04-03 23:16
     */
    public static function singleton()
    {
        if(is_null(static::$singleton)){
            static::$singleton = new static();
        }
        return static::$singleton;
    }


    /**
     * 获取监听列表
     * @return array
     *
     * @author liu.bin 2020-05-06 22:32
     */
    public function getListenerList()
    {
        return $this->_listenList;
    }


    /**
     * 添加端口监听
     * @param Listen $listener
     * @author liu.bin 2020-04-14 16:16
     */
    public function listen(Listen $listener)
    {
        array_push($this->_listenList,$listener);
    }


    /**
     * run
     *
     * @author liu.bin 2020-04-30 16:22
     */
    public static function run()
    {
        // 初始化空间
        Grant::processInit(self::singleton()->num);
        Grant::connectInit(60);
        //
        self::singleton()->loop();
    }


}